<script type="text/javascript"><!--//--><![CDATA[//><!--

 	$(document).ready(function() {
		// Setup Form
		$('#form_master').setupForm([
			{ name: 'kode_promosi', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'tanggal_permintaan', type: 'date', size: 'short', maxlength: 10, noempty:true },
			{ name: 'id_departemen_pk', type: 'lov', size: 'short',
				onClearButton:function(){
					$(this).setval(''); 
					$('#nama_departemen').setval(''); 
				},
				onActionButton:function(){ 
					LOVDepartemen({ onSelect:function(row){ 
						$('#id_departemen_pk').setval(row.id_departemen_pk); 
						$('#nama_departemen').setval(row.nama_departemen); 
					} }); 
				}
			},
			{ name: 'nama_departemen', type: 'text', size: 'medium', maxlength: 20, readonly:true },
			{ name: 'status_permintaan', type: 'text', size: 'long', maxlength: 200, noempty:true },
			{ name: 'nama_desain', type: 'text', size: 'long', maxlength: 200, noempty:true },
			{ name: 'jenis_desain', type: 'text', size: 'long', maxlength: 200, noempty:true },
			{ name: 'keterangan', type: 'text', size: 'long', maxlength: 200, noempty:true },
		], <?php echo json_encode($data); ?>);

        
        
		
        <?php if($mode=="edit"){ ?>
        $('#kode_promosi').readonly();
        <?php } ?>
		
		var buttons = [{ label: 'Save', icon: 'save', onclick: function() { 
                            jenis_desain_arr = $('.jenis_desain_arr');
                            jenis_desain = '';
                            for (var i = 0; i < jenis_desain_arr.length; i++) {
                                jenis_desain += "++/n"+jenis_desain_arr[i].value;
                            };
                            $('#jenis_design_val').setval(jenis_desain.substring(4));
							$('#form_master').submitForm(	'/'+controller+'/ajax_post' );
                            loadPage('/'+controller+'/Index'); }/*, onclick: function() { loadPage('/'+controller+'/Index');} */
						},
					   { label: 'Close', icon: 'cancel', onclick: function() { loadPage('/'+controller+'/Index'); } }];
		setAction(buttons);

		
    });




//--><!]]></script>

<script type="text/javascript">
var counter = 1;

function remAppend(val){
    value = val.id;
    jenis_d = value.replace("btnRem", "jenis_desain");
    $('#'+jenis_d).remove();
    $(val).remove();
}

$("#append").click( function() {
    $("#div_group").append("<input id='jenis_desain"+counter+"' class='textfield long noempty jenis_desain_arr' /><input type='button' value='Remove' id='btnRem"+counter+"' onclick='remAppend(this)'><br>");
    counter++;
    return false;
});

<?php
    if ($data['jenis_desain']) {
        $arr_jenis_desain = explode('++/n', $data['jenis_desain']);
        ?>
        counter = <?php echo (count($arr_jenis_desain) + 1) ?>;
        <?php
        for ($i = 0; $i < count($arr_jenis_desain); $i++) {
            ?>
                $("#div_group").append("<input id='jenis_desain<?php echo ($i + 1); ?>' value='<?php echo $arr_jenis_desain[$i]; ?>' class='textfield long noempty jenis_desain_arr' /><input type='button' value='Remove' id='btnRem<?php echo ($i + 1); ?>' onclick='remAppend(this)'><br>");
            <?php
        };
    }
?>

</script>

<div id="form_master_message" style="display:none;"></div>
    <table class="tb_form" style="display:none;" cellpadding="0" cellspacing="0">
    <tr>
        <td class="label" style="width:150px">Kode Promo</td>
        <td colspan="2"><input id="kode_promosi" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Tanggal Permintaan</td>
        <td colspan="2"><input id="tanggal_permintaan" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">ID Departemen</td>
        <td colspan="2"><input id="id_departemen_pk" /><input id="nama_departemen" name="nama_departemen" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Status Permintaan</td>
        <td>
        	<select id="status_permintaan" name="status_permintaan">
				<option value="Sudah Dikerjakan" > Sudah Dikerjakan</option>
                <option value="Belum Dikerjakan" > Belum Dikerjakan</option>
			</select>
        </td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Nama Desain</td>
        <td colspan="2"><input id="nama_desain" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Jenis Desain</td>
        <td colspan="2">
            <div id="div_group">

            </div>  
            <input type="hidden" name="jenis_desain" id="jenis_design_val"/>
            <input type="button" id="append" value="Tambah" />
        </td>
    </tr>   
    <tr>
        <td class="label" style="width:150px">Keterangan</td>
        <td colspan="2"><textarea name ="keterangan" id="keterangan" /></td>
    </tr>
    </table>